﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace Collection.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine($"=====blocking collection demo=====");
            //BlockingCollectionDemo.Run().Wait();

            //Console.WriteLine($"=====bag collection demo=====");
            //ConcurrentBagDemo.Run();

            //RandomDemo.Bad_Random();
            //RandomDemo.Good_Random_In_SingleThread();
            //RandomDemo.Bad_Random_In_MultThreads();
            //RandomDemo.Good_Random_In_MultThreads();

            //ExpressionSample expSample = new ExpressionSample();
            //expSample.RegisterDuration_Sample();

            //ThreadsSample threadsSample = new ThreadsSample();
            //threadsSample.Run(2);


            CancellationTokenSource cts = new CancellationTokenSource();

            _ = Task.Factory.StartNew((t) =>
            {
                var ct = (CancellationToken)t;
                while (!ct.IsCancellationRequested)
                {
                    Task.Delay(TimeSpan.FromSeconds(1)).Wait();
                    Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId} i am running");
                }

            }, cts.Token, cts.Token);

            Task.Delay(TimeSpan.FromSeconds(2)).Wait();

            cts.Cancel();

            //SemaphoreSample semaphoreSample = new SemaphoreSample();
            //semaphoreSample.Run();


            Console.WriteLine("end!");
            Console.ReadLine();
        }
    }
}
